package com.baizhi.service.impl;

import com.baizhi.dao.CmfzResourceDao;
import com.baizhi.dao.CmfzRoleDao;
import com.baizhi.service.CmfzShiroService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
/*
 * 该业务：使用shiro对持明法洲项目进行管理员进行权限认证管理
 * */
@Slf4j
@Service
@Transactional(readOnly = true)
public class CmfzShiroServiceImpl implements CmfzShiroService {
    //装配dao对象
    @Autowired
    private CmfzRoleDao cmfzRoleDao;
    @Autowired
    private CmfzResourceDao cmfzResourceDao;

    //三表查询  根据管理员账户名查询其所拥有的角色名
    @Override
    public Set<String> selectRoleNameByUsername(String username) {
        List<String> list = cmfzRoleDao.selectRoleNameByUsername(username);
        Set<String> set = new HashSet<>();
        for (String s : list) {
            set.add(s);
        }
        return set;
    }

    //五表查询  根据管理员账户名 查询其拥有的权限
    @Override
    public Set<String> selectResourcePermission(String username) {
        List<String> list = cmfzResourceDao.selectResourcePermission(username);
        Set<String> set = new HashSet<>();
        for (String s : list) {
            set.add(s);
        }
        return set;
    }
}
